//
// Created by whitby on 8/22/23.
//

#ifndef MONO_ORB_SLAM2_MAP_H
#define MONO_ORB_SLAM2_MAP_H

#include "KeyFrame.h"
#include <set>

namespace mono_orb_slam2 {

    class KeyFrame;

    class MapPoint;

    class Map {
    public:
        void addKeyFrame(const std::shared_ptr<KeyFrame> &keyFrame);

        void eraseKeyFrame(const std::shared_ptr<KeyFrame> &keyFrame);

        void addMapPoint(const std::shared_ptr<MapPoint> &mapPoint);

        void eraseMapPoint(const std::shared_ptr<MapPoint> &mapPoint);

        std::vector<std::shared_ptr<KeyFrame>>
        getRecentKeyFrames(const std::shared_ptr<KeyFrame> &curKeyFrame, int num = 20);

        int getNumKeyFrames();

        int getNumMapPoints();

        std::vector<std::shared_ptr<KeyFrame>> getAllKeyFrames();

        std::vector<std::shared_ptr<MapPoint>> getAllMapPoints();

        void setReferenceMapPoints(const std::vector<std::shared_ptr<MapPoint>> &mapPoints);

        std::set<std::shared_ptr<MapPoint>> getReferenceMapPoints();

        void clear();

        std::mutex map_update_mutex;

    protected:
        std::set<std::shared_ptr<KeyFrame>> keyframes;
        std::set<std::shared_ptr<MapPoint>> map_points;

        std::vector<std::shared_ptr<MapPoint>> reference_map_points;

        std::mutex map_mutex;
    };

} // mono_orb_slam2

#endif //MONO_ORB_SLAM2_MAP_H
